#pragma once

namespace Tmpl {

struct MapPosTexture
{
	char texId;
	float value;
};

struct MapPos
{
	float height;
	MapPosTexture textures[MAX_TEXTURES_PER_POS];
};

class Image;
struct MapTexture
{
	char name[256];
	unsigned int textureId;
	float density;
	float slopeMin, slopeMax;
	float heightMin, heightMax;
};

class ShaderProgram;
class WorldMap
{
public:
	WorldMap(int mapSize, int renderSize);
	~WorldMap();

	void GenerateMap(int seed);
	void Update(Vec3f playerPos);
	void Render(Matrix4x4f projection, Matrix4x4f modelView);
	float GetHeightAtPos(Vec2f pos);

	char AddTexture(const char* filename, float density=0.0f, float slopeMin=0.0f, float slopeMax=0.0f, float heightMin=0.0f, float heightMax=0.0f);

	int GetTriangleCount(){return mRenderSize*mRenderSize*2;}
private:
	void BindVBO(ShaderProgram* shader);
	void UnbindVBO(ShaderProgram* shader);

	void RenderFlat(Matrix4x4f projection, Matrix4x4f modelView);
	void RenderTextured(Matrix4x4f projection, Matrix4x4f modelView);

	MapPos& GetMap(int x, int y);

	// Map Data
	int mSeed;
	int mMapSize;
	MapPos* mMap;

	// Texture Data
	MapTexture* mTextures;
	int mTextureCount;

	// Render Data
	int mRenderSize;
	ShaderProgram* mShader;
	ShaderProgram* mShaderFlat;
	unsigned int mVBO;
	unsigned int mVBOIndices;
	int mVboStrideSize;
	char mRenderTextures[MAX_RENDER_TEXTURES];
	char mRenderTextureCount;
};

}; // namespace Tmpl